package com.zznj.xzjc.adapter.index;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zznj.xzjc.R;
import com.zznj.xzjc.bean.index.KnowledgeAndWorkBasic;
import com.zznj.xzjc.bean.index.OrgBean;
import com.zznj.xzjc.utils.StringUtils;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class OrgAdapter extends BaseQuickAdapter<OrgBean, BaseViewHolder> {

    public OrgAdapter(int layoutResId, @Nullable List<OrgBean> data) {
        super(layoutResId, data);
    }

    private String selectOrgId;
    public void setSelectOrgId(String id){
        this.selectOrgId = id;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, OrgBean item) {
        helper.setText(R.id.title,item.getTitle());
        List<KnowledgeAndWorkBasic> basic = new Gson().fromJson(item.getBasicInfo(),new TypeToken<List<KnowledgeAndWorkBasic>>(){}.getType());
        String leader = "";
        String dizhi = "";
        if(basic.size() > 0){
            for(int i=0;i<basic.size();i++){
                if(basic.get(i).getName().equals("单位领导")){
                    leader = basic.get(i).getValue();
                    if(!StringUtils.isEmpty(dizhi)){
                        break;
                    }
                }
                if(basic.get(i).getName().equals("办公地址")){
                    dizhi = basic.get(i).getValue();
                    if(!StringUtils.isEmpty(leader)){
                        break;
                    }
                }
            }
        }
        helper.setText(R.id.info,"领导："+StringUtils.toStringForWu(leader)+"      地址："+StringUtils.toStringForWu(dizhi));
        ImageView selectImg = helper.getView(R.id.selectImg);
        if(item.getId().equals(selectOrgId)){
            selectImg.setVisibility(View.VISIBLE);
        }else{
            selectImg.setVisibility(View.GONE);
        }

    }
}
